package com.tubruk.util.dialog;

import java.util.ArrayList;

import com.tubruk.adapter.MenuAdapter;
import com.tubruk.object.PopMenu;
import com.tubruk.trackme.R;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

public class ListMenu extends Dialog {

	private static final String DEFAULT_TITLE = "OPTIONS";
	private String title;
	
	private ArrayList<PopMenu> items;
	private MenuAdapter adapter;
	
	public interface ListMenuListener {
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3);
	}
	
	private ListMenuListener listener;
	
	public ListMenu(Context context, ListMenuListener listener) {
        super(context);
        this.listener = listener;
        this.title = ListMenu.DEFAULT_TITLE;
    }
	
	public ListMenu(Context context, ListMenuListener listener, ArrayList<PopMenu> items) {
        super(context);
        this.items = items;
        this.listener = listener;
        this.title = ListMenu.DEFAULT_TITLE;
    }
	
	public ListMenu(Context context, ListMenuListener listener, ArrayList<PopMenu> items, String title) {
		super(context);
	    this.items = items;
		this.listener = listener;
		this.title = title;
	}

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listmenu_dialog);
        setTitle(title);
        
    	ListView list = (ListView) this.findViewById(R.id.ListView);
    	
    	//items = new ArrayList<PopMenu>();
		adapter = new MenuAdapter(getContext(), R.id.ListView, items);
		
		list.setAdapter(adapter);
		list.setOnItemClickListener(new ItemClickListener());
    }
    
    public ArrayList<PopMenu> getItems(){
    	return items;
    }
    
    private class ItemClickListener implements ListView.OnItemClickListener {
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			listener.onItemClick(arg0, arg1, arg2, arg3);
			dismiss();
		}
    }
    
}
